﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="VacationEdit.aspx.cs" Inherits="Web.VacationEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>请假申请 编辑</title>
    <base target="_self" />
    <meta content="ie=7" http-equiv="x-ua-compatible">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <link href="Styles/Style01.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/jquery-1.7.min.js" type="text/javascript"></script>
    <link href="Styles/validate.css" rel="stylesheet" type="text/css" />
    <script src="Scripts/easy_validator.pack.js" type="text/javascript"></script>
    <script>
        //iframe高度自适应
        function IFrameReSize(iframename) {
            var pTar = document.getElementById(iframename);
            if (pTar) {  //ff
                if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
                    pTar.height = pTar.contentDocument.body.offsetHeight;
                } //ie
                else if (pTar.Document && pTar.Document.body.scrollHeight) {
                    pTar.height = pTar.Document.body.scrollHeight;
                }
            }
        }
        //iframe宽度自适应
        function IFrameReSizeWidth(iframename) {
            var pTar = document.getElementById(iframename);
            if (pTar) {  //ff
                if (pTar.contentDocument && pTar.contentDocument.body.offsetWidth) {
                    pTar.width = pTar.contentDocument.body.offsetWidth;
                }  //ie
                else if (pTar.Document && pTar.Document.body.scrollWidth) {
                    pTar.width = pTar.Document.body.scrollWidth;
                }
            }
        }

        //取get参数
        function getArg() {
            var url = unescape(window.location.href);
            var allArgs = url.split("?")[1];
            if (allArgs != null) {
                var args = allArgs.split("&");
                for (var i = 0; i < args.length; i++) {
                    var arg = args[i].split("=");
                    eval('this.' + arg[0] + '="' + arg[1] + '";');
                }
            }
        }
        var urlArg = new getArg();
        var formNo = urlArg.formNo;

        $(function () {
            $("[reg]").parents("td").prev().append("<font color='#ff0000'>*</font>");
            $("#btnSave").click(function () {
                return formValid();
            });
            $("#btnSubmit").click(function () {
                var trs = $("#tbDetail tbody").find("tr");
                if (trs.length == 0) { alert('请增加 请假明细~'); return false; }
                return formValid();
            });
            
            if ($("#VacationType").val() == "调休") {
                $("#ReplacedDay").removeAttr("disabled");
                $("#trExchange").show();
            }
            $("#VacationType").change(
                function () {
                    if ($(this).val() == "调休") {
                        $("#ReplacedDay").removeAttr("disabled");
                    } else {
                        $("#ReplacedDay").attr("disabled", "True");
                    }
                });
        });
        function formValid() {
            var isSubmit = true;
            $("form").find("[reg],[url]:not([reg])").each(function () {
                if (!validate($(this), this.tagName)) {
                    isSubmit = false;
                }
            });
            if (!isSubmit) {
                alert("请确认'红字或红框'处的输入正确!");
                return false;
            }
            if ($("#VacationType").val() == "调休" && $("#ReplacedDay").val() == "") {
                alert("请输入对应的'值班加班时间'");
                return false;
            }
            if ($("#VacationType").val() == "调休" && parseFloat($("#DaysCnt").val()) != "1" && parseFloat($("#DaysCnt").val()) != "2") {
                alert("一次只允许调休1天或2天");
                return false;
            }
            var re = /^[0-9]+.?[0-9]*$/;
            if ($("#VacationType").val() == "年假" && !re.test($("#DaysCnt").val())) {
                alert("年假休假必须是整数");
                return false;
            }
            return true;
        }
        function detailEdit(id) {
            var url = 'VacationDetailEdit.aspx?formNo=' + formNo;
            if (id != undefined) {
                url = 'VacationDetailEdit.aspx?id=' + id;
            }
            var retVal = window.showModalDialog(url, window, 'dialogWidth=550px;dialogHeight=550px;status=no;help=no;resizable=yes;');
            if (retVal != undefined && retVal.indexOf('Succeed') >= 0) {
                window.name = "__self";
                window.open(window.location.href, "__self");
            }
        }
        function detailDel(id) {
            if (confirm('您确定删除该行记录吗?')) {
                $.ajax({ type: 'post', url: "/Vacation.mvc/DelDetail", data: { id: id },
                    success: function (data, textStatus) {
                        if (data == "Succeed") {
                            window.name = "__self";
                            window.open(window.location.href, "__self");
                        }
                    }
                });
            }
        }
    </script>
</head>
<body>
<form id="Form1" runat=server><input type=hidden runat=server id=FormNo />
<table class="s1">
<tr><td>表单编号</td><td><%=reqVacationMain.FormNo%></td><td>申请时间</td><td><%=reqVacationMain.ReqDate.ToString("yyyy-MM-dd HH:mm:ss")%></td></tr>
<tr><td>申请人</td><td><%=empName%></td><td>请假类型</td>
<td><select id="VacationType" runat="server" title="不能为空" reg=".">
<option value="">请选择</option>
<option value="事假">事假</option>
<option value="病假">病假</option>
<option value="婚假">婚假</option>
<option value="丧假">丧假</option>
<option value="年假">年假</option>
<option value="公假">公假</option>
<option value="调休">调休</option>
<option value="产假">产假</option>
<option value="陪产假">陪产假</option>
<option value="外勤">外勤</option>
</select></td></tr>
<tr>
    <td>已批年假(天)</td><td><label id="lblNianJia" name="lblNianJia" runat="server"></label></td>
    <td>总年假(天)</td><td><label id="lblNianJiaTotal" name="lblNianJiaTotal" runat="server"></label></td>
</tr>
    <tr><td>总天数</td><td><input id="DaysCnt" runat="server" title="整数或带一位小数" reg="^\d+\.?\d?$"/></td><td></td><td></td></tr>
    <tr><td>值班、加班时间</td><td colspan=3><input id="ReplacedDay" runat="server" disabled="True"/></td></tr>
    <tr id="trExchange" name="trExchange" style="display:none;background:#ffff99;">
        <td colspan="2">
            <asp:Repeater ID="rptList0" runat="server">
                <HeaderTemplate>
                    <table border="0px" cellpadding="0px" cellspacing="0px">
				    <tr>
					    <th width="30%">休息开始时间</th>
					    <th width="30%">休息结束时间</th>
					    <th>对应加班时间说明</th>
				    </tr>
                </HeaderTemplate>
                <ItemTemplate>
				    <tr>
					    <td><%#Eval("PreStartTime")%></td>
					    <td><%#Eval("PreEndTime")%></td>
					    <td><%# string.IsNullOrWhiteSpace(Eval("Remarks").ToString()) ? "&nbsp;" : Eval("Remarks")%></td>
				    </tr>
                </ItemTemplate>
                <FooterTemplate>
                </table>
                </FooterTemplate>
            </asp:Repeater>
        </td>
        <td colspan="2">
            <table border="0px" cellpadding="0px" cellspacing="0px">
                <tr>
                <th width="30%">加班开始时间</th>
                <th width="30%">加班结束时间</th>
                <th>加班原因</th>
                </tr>
            <asp:Repeater ID="rptList2" runat="server">
                <ItemTemplate>
				    <tr>
					    <td><%#Eval("PreStartTime")%></td>
					    <td><%#Eval("PreEndTime")%></td>
					    <td><%# string.IsNullOrWhiteSpace(Eval("Cause").ToString()) ? "&nbsp;" : Eval("Cause")%></td>
				    </tr>
                </ItemTemplate>
            </asp:Repeater>
            <asp:Repeater ID="rptList3" runat="server">
                <ItemTemplate>
                <tr>
                <td><%#Eval("dutydate")%></td>
                <td><%#Eval("dutydate")%></td>
                <td>值班</td>
                </tr>
                </ItemTemplate>
            </asp:Repeater>
            </table>
        </td>
    </tr>
</table>
<asp:Repeater ID="rptList" EnableViewState="false" Runat="server">
	<HeaderTemplate>
		<table id="tbDetail" class="s1 list">
			<caption>请假明细<input type=button onclick="javascript:detailEdit();" value="添加明细"/></caption>
			<thead>
				<TR>
					<th width="25%">预计开始时间</th>
					<th width="25%">预计结束时间</th>
					<th width="20%">备注</th>
					<th class="tdOrder">操作</th>
				</TR>
			</thead><tbody>
	</HeaderTemplate>
	<ItemTemplate>
		<tr class="<%# Container.ItemIndex%2==0?"bg":""%>">
			<td><%#Eval("PreStartTime")%></td>
			<td><%#Eval("PreEndTime")%></td>
			<td><%#Eval("Remarks")%></td>
			<td>
                <a href="#" onclick="detailEdit(<%# DataBinder.Eval(Container.DataItem,"Id") %>);return false;">[编辑]</a>
                <a href="#" onclick="detailDel(<%# DataBinder.Eval(Container.DataItem,"Id") %>);return false;">[删除]</a>
			</td>
		</tr>
	</ItemTemplate>
	<FooterTemplate>
		</tbody> </table>
	</FooterTemplate>
</asp:Repeater>
<div style="text-align:right;margin-right:24px;margin-top:6px;">
    <asp:button runat="server" text="保存" class="btn" id="btnSave" onclick="btnSave_Click"/>
    <asp:button runat="server" text="提交" class="btn" id="btnSubmit" onclick="btnSubmit_Click"/>
    <input type=button value="关闭" class="btn" onclick="window.close();" />
</div>
</form>
</body>
</html>